package ac.svn.accesscontrol.main;

import java.lang.reflect.InvocationTargetException;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import ac.notification.manager.NotificationRegistrar;
import ac.svn.accesscontrol.controller.UserInfoController;
import ac.svn.accesscontrol.manager.InitManager;
import ac.svn.accesscontrol.ui.window.ProgressGlassPane;
import ac.svn.accesscontrol.ui.window.SplashScreen;
import ac.svn.accesscontrol.utils.Utility;

public class Main {

	/**
	 * @param args
	 * @throws InvocationTargetException 
	 * @throws InterruptedException 
	 * @throws UnsupportedLookAndFeelException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws InterruptedException, InvocationTargetException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
		NotificationRegistrar.setLogging(true);
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Unable to load Custom look and feel, Window might look different!", "Look n Feel load failed!", JOptionPane.WARNING_MESSAGE);
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}


		final SplashScreen screen = new SplashScreen();
		//screen.setVisible(true);
		ProgressGlassPane glassPane = new ProgressGlassPane();
		screen.setGlassPane(glassPane);
		glassPane.setVisible(true);
		glassPane.waitForTime(300);

		System.out.println("Starting InitManager...");
		final InitManager initManager = new InitManager();
		System.out.println("Starting UserInformation Manager..");
		UserInfoController userInfoController = new UserInfoController();

		initManager.getMainWindow().setVisible(true);
		Thread startupThread = new Thread(new Runnable() {

			@Override
			public void run() {
				try 
				{
					Thread.sleep(1000);
				}
				catch (InterruptedException e) 
				{
					e.printStackTrace();
				}

				initManager.getMainWindow().setVisible(true);
				try 
				{
					Thread.sleep(0);
				}
				catch (InterruptedException e) 
				{
					e.printStackTrace();
				}
				screen.setVisible(false);
				Utility.showSystemNotification("SMART CM started successfully!");
			}
		});
		startupThread.start();

	}

}
